﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace CrystalCore.Actors
{
    public class PlayerSpottedEventArgs : EventArgs
    {
        public Elemental Finder;

        public PlayerSpottedEventArgs(Elemental finder)
        {
            this.Finder = finder;

        }
    }

    public sealed class Director
    {
        //Fields
        private List<Elemental> _ListOfElementals;
        public event EventHandler<PlayerSpottedEventArgs> OnPlayerSpotted;

        //ctor
        public Director()
            : this(new List<Elemental> { })
        {

        }

        public Director(IEnumerable<Elemental> elementals)
        {
            _ListOfElementals = new List<Elemental>();
            this.Add(elementals.ToArray());
        }

        //Methods
        public IEnumerable<T> GetByType<T>() where T : Elemental
        {
            return _ListOfElementals.Where(e => e is T).Select(e => e as T);
        }
        public void Add(params Elemental[] elementals)
        {
            foreach (Elemental e in elementals)
                e.OnPlayerSpotted += this.OnPlayerSpotted;

            _ListOfElementals.AddRange(elementals);
        }

        public void UpdateAll(GameTime time)
        {
            foreach (Elemental e in _ListOfElementals)
            { 
                e.UpdateActor(time); 
            }
        }
        public void RenderAll(GameTime time)
        {
            foreach (Elemental e in _ListOfElementals)
                e.DrawActor(time);
        }
    }
}
